/*
 * $Id: DigitalServiceFilter.java,v 1.2 2009/10/02 21:13:26 navdeep_mahajan Exp $
 * 
 * Copyright (C) 2006 General Electric Company. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of the General
 * Electric Company (GE). You shall not disclose this software and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with GE.
 * 
 * GE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. GE SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */
package com.ge.healthcare.autosc.processor.dispatcher.tasks.filter;

import com.ge.healthcare.autosc.common.ASCLogger;
import com.ge.healthcare.autosc.common.database.pojo.ActRequest;
import com.ge.healthcare.autosc.common.database.pojo.ActTask;
import com.ge.med.service.eds.macdata.ISystem;
import com.ge.med.service.eds.macdata.InterfaceObjectFactory;
import com.ge.med.service.eds.macdata.MacDataException;

public class DigitalServiceFilter implements TaskFilter {
	public TaskFilterResults isEnabled(ActRequest request) {
		TaskFilterResults result = null;
		try {
			result = new TaskFilterResults("Digial Service Filter Request:");
			result.append("SystemId: " + request.getSystemId());
			ISystem system = InterfaceObjectFactory.getDefaultInstance()
					.getSystem();
			result.setEnabled(system.isDSEnabled(request.getSystemId()));
			result.append(" Enabled: " + result.isEnabled());
		} catch (MacDataException me) {
			result.append(errorText(me));
		} catch (Exception me) {
			result.append(errorText(me));
		}
		return result;
	}

	public TaskFilterResults isEnabled(ActTask task) {
		TaskFilterResults result = new TaskFilterResults(
				"Digial Service Filter Task: No Use Case not implmented");
		return result;
	}

	private StringBuffer errorText(Exception e) {
		StringBuffer msg = new StringBuffer();
		msg.append("DS Enablement check couldn't be performed on the System.");
		msg.append(" Files will not be copied to DS Pool.");
		msg.append(" Caught Exception : ").append(e.getMessage());
		ASCLogger.error(this.getClass(), "errorText", msg, e);
		return msg;
	}
}
